<template>
  <div>
    <p class="pinformation" style="margin-top: 7px;">搜索条件</p>
    <el-form label-width="80" :model="queryParams" ref="queryRef">
      <el-row>
        <el-col :span="4">
          <el-form-item label="方案编号：" prop="projectCode">
            <el-input v-model="queryParams.projectCode" clearable maxlength="100" @keyup.enter="handeleQuery" placeholder="请输入方案编号"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="方案名称：" prop="projectName" label-width="105">
            <el-input v-model="queryParams.projectName" clearable maxlength="100" @keyup.enter="handeleQuery" placeholder="请输入方案名称"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-form-item label="受检单位：" prop="sjCustomName">
            <el-input v-model="queryParams.sjCustomName" clearable maxlength="100" @keyup.enter="handeleQuery"  placeholder="请输入受检单位"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-form-item label="合同编号：" prop="contractCode" label-width="105">
            <el-input v-model="queryParams.contractCode" clearable maxlength="100" @keyup.enter="handeleQuery"  placeholder="请输入合同编号"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="合同名称：" prop="contractName">
            <el-input v-model="queryParams.contractName" clearable maxlength="100" @keyup.enter="handeleQuery"  placeholder="请输入合同名称"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="4">
          <el-form-item label="方案类型：" prop="contractType">
            <el-select clearable v-model="queryParams.contractType" style="width: 100%;">
              <el-option
                v-for="dict in proxy.addListNoLimit(sys_contract_type)"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="是否变更合同：" prop="degree" label-width="105">
            <el-select clearable v-model="queryParams.degree">
              <el-option
                v-for="dict in proxy.addListNoLimit(sys_degree)"
                :key="dict.value"
                :label="dict.label"
                :value="parseInt(dict.value)"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-form-item label="委托单位：" prop="wtCustomName">
            <el-input v-model="queryParams.wtCustomName" clearable maxlength="100" @keyup.enter="handeleQuery"  placeholder="请输入委托单位"></el-input>
          </el-form-item>
        </el-col>
        <!-- ！ -->
        <el-col :span="5">
          <!-- planDate -->
          <el-form-item label="方案开始时间：" label-width="105">
            <el-date-picker
              v-model="dateRange"
              value-format="YYYY-MM-DD"
              type="daterange"
              :clearable="false"
              :editable="false"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="申请状态：" prop="degree">
            <el-select clearable v-model="queryParams.degree">
              <el-option
                v-for="dict in proxy.addListNoLimit(sys_degree)"
                :key="dict.value"
                :label="dict.label"
                :value="parseInt(dict.value)"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="2">
          <el-row justify="center">
            <el-button type="success" @click="handeleQuery">搜索</el-button>
            <el-button class="business resetBtn" @click="resetQuery">重置</el-button>
          </el-row>
        </el-col>
      </el-row>
    </el-form>
    <el-row>
        <p class="pinformation">方案列表</p>
        <p class="totalStyle">共 {{ total }} 条数据</p>
    </el-row>
    <el-table ref="mainTableRef" :data="projectList">
      <el-table-column prop="projectCode" label="方案编号" align="center" />
      <el-table-column prop="projectName" label="方案名称" align="center" />
      <el-table-column prop="contractCode" label="合同编号" align="center" />
      <el-table-column prop="wtCustomName" label="委托单位" align="center" />
      <el-table-column prop="planDate" label="方案开始时间" align="center" />
      <el-table-column prop="requireDate" label="变更申请时间" align="center" />
      <el-table-column prop="requireDate" label="变更申请人" align="center" />
      <el-table-column label="方案类型" align="center">
        <template #default="scope">
          <dict-tag :options="sys_contract_type" :value="scope.row.contractType" />
        </template>
      </el-table-column>
      <el-table-column label="是否变更合同" align="center">
        <template #default="scope">
          <dict-tag :options="sys_degree" :value="scope.row.degree" />
        </template>
      </el-table-column>
      <el-table-column label="申请状态" align="center">
        <template #default="scope">
          <dict-tag :options="sys_degree" :value="scope.row.degree" />
        </template>
      </el-table-column>
      <el-table-column prop label="操作" align="center">
        <template #default="scope">
          <el-button link type="success" icon="Edit" v-if="!props.step" @click="review(scope.row)">编辑</el-button>
          <!-- <el-button link type="success" v-if="props.step" @click="review(scope.row)">签审</el-button> -->
          <!-- <el-button link type="success" v-if="props.step" @click="review(scope.row)">删除</el-button> -->
          <el-button link type="success" icon="View" v-if="props.step" @click="review(scope.row)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="handeleQuery"
    />
  </div>
</template>

<script setup>
import { getProjectReviewList } from "@/api/project/projectCheck";

const { proxy } = getCurrentInstance();
const {  sys_degree, sys_project_step } = proxy.useDict(
  "sys_degree",
  "sys_project_step"
);
const {
  sys_contract_type,
} = proxy.useOrgDict(
  "sys_contract_type",
);
const projectList = ref([]);
const total = ref(0);
const dateRange = ref([]);
const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    stepId: 1,
    contractType: -1,
    degree: -1
  }
});
const { queryParams, form } = toRefs(data);
const props = defineProps({
  step: {
    type: Number //参数类型
  }
});
const emits = defineEmits(["projectId","projectId2"]);

function handeleQuery() {
  queryParams.value.stepId = props.step || 1
  getProjectReviewList(proxy.addDateRange(queryParams.value, dateRange.value)).then(res => {
    projectList.value = res.rows;
    total.value = res.total;
  });
}

function review(row) {
  emits("projectId", row.projectId);
}

function resetQuery() {
  proxy.resetForm('queryRef')
  dateRange.value = [];
  handeleQuery();
}

defineExpose({
  getTableHeight
})

watch(()=>total.value,()=> {
  if (total.value) {
    heightParams.value = [{tableName: "main", bottomHeight: 73}]
  } else {
    heightParams.value = [{tableName: "main", bottomHeight: 22}]
  }
  getTableHeight()
})

const heightParams = ref([{ tableName: "main", bottomHeight: 22 }]);
function getTableHeight() {
  proxy.adaptiveHeight(proxy, heightParams.value);
}
onMounted(() => {
  nextTick(() => {
    getTableHeight();
    window.addEventListener("resize", getTableHeight);
  })
})
onUpdated(() => {
  nextTick(function() {
    getTableHeight();
  });
});
onBeforeUnmount(() => {
  window.removeEventListener("resize", getTableHeight);
});
handeleQuery();
</script>

<style>
</style>